package org.budo.mongo.jdbc.driver.statement.impl;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map;

import org.budo.jdbc.driver.AbstractBudoJdbcPreparedStatement;
import org.budo.jdbc.driver.resultset.impl.MapArrayResultSet;
import org.budo.mongo.jdbc.driver.BudoMongoJdbcConnection;
import org.budo.mongo.jdbc.driver.BudoMongoJdbcPreparedStatement;
import org.budo.mongo.jdbc.driver.statement.AbstractMongoStatement;

import com.mongodb.client.MongoDatabase;

/**
 * 展示视图列表
 * 
 * @author lmw
 */
public class SHOW_FULL_TABLES extends AbstractMongoStatement {
    @Override
    public void execute(PreparedStatement preparedStatement) throws SQLException{
        try {
            BudoMongoJdbcPreparedStatement mongoPreparedStatement = (BudoMongoJdbcPreparedStatement) preparedStatement;
            BudoMongoJdbcConnection mongoConnection = (BudoMongoJdbcConnection) mongoPreparedStatement.getConnection();
            MongoDatabase mongoDatabase = mongoConnection.mongoDatabase();
            String[] columnNames = new String[] { "Tables_in_" + mongoDatabase.getName(), "Table_type" };
            ResultSet resultSet = new MapArrayResultSet(columnNames, new Map[0]);
            ((AbstractBudoJdbcPreparedStatement) preparedStatement).resultSet(resultSet);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}